{php}$title= '笔记信息';{/php}
{include file="layout/header"}
<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <form action="{:url('/admin/notes/queryapp')}" method="post">
                            <div class="form-group">
                                <label for="id">笔记id</label>
                                <input type="text" class="form-control" id="id" value="{$notes.id}" disabled>
                            </div>
                            <div class="form-group">
                                <label for="appname">笔记标题</label>
                                <input type="text" class="form-control" id="title" value="{$notes.title}"
                                    placeholder="请输入应用名称">
                            </div>
                            <div class="form-group">
                                <label for="hierarchy">笔记内容</label>
                                <textarea class="form-control" aria-label="With textarea" id="content"
                                    placeholder="笔记内容" style="height: 200px;">{$notes.content}</textarea>
                            </div>
                            <div class="form-group">
                                <label for="ip">提交ip地址</label>
                                <input type="text" class="form-control" id="ip" value="{$notes.ip}" disabled>
                            </div>
                            <div class="form-group">
                                <label for="creattime">创建时间</label>
                                <input type="text" class="form-control" id="creattime" value="{$notes.creattime}" disabled>
                            </div>
                            <div class="form-group">
                                <label for="updatetime">最新修改时间</label>
                                <input type="text" class="form-control" id="updatetime" value="{$notes.updatetime}" disabled>
                            </div>
                            <div class="form-group">
                                <label for="username">创建用户</label>
                                <input type="text" class="form-control" id="username" value="{$notes.username}" disabled>
                            </div>
                            
                            <div class="form-group">
                                <label for="appname">应用名称</label>
                                <input type="text" class="form-control" id="appname" value="{$notes.appname}" disabled>
                            </div>
                            <button type="button" onclick="updateapp()" class="btn btn-w-sm btn-primary mb-2">提交</button>
                            <button type="button" class="btn btn-default mb-2"
                                onclick="javascript:history.back(-1);return false;">返 回
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
</div>
</div>
{include file="layout/footer"}
<script>
    function updateapp() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var id = $.trim($("#id").val());
        var title = $.trim($("#title").val());
        var content = $.trim($("#content").val());
        $.ajax({
            type: "POST",
            url: "{:url('notes/editnote')}",
            data: {
                id: id,
                title: title,
                content: content
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 200) {
                    $.notify({
                        message: data.msg
                    }, {
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        type: 'success'
                    });
                } else {
                    $.notify({
                        message: data.msg
                    }, {
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        // settings
                        type: 'danger'
                    });
                }
            }
        })
    }

    $(document).ready(function () {
        $(document).on('click', '.file-browser', function () {
            var $browser = $(this);
            var file = $browser.closest('.file-group').find('[type="file"]');
            file.on('click', function (e) {
                e.stopPropagation();
            });
            file.trigger('click');
        });

        $(document).on('change', '.file-group [type="file"]', function () {
            var l = $('body').lyearloading({
                opacity: 0.2,
                spinnerSize: 'lg',
                spinnerText: '后台处理中，请稍后...',
                textColorClass: 'text-info',
                spinnerColorClass: 'text-info'
            });
            var $this = $(this);
            var $input = $(this)[0];
            var $len = $input.files.length;
            var formFile = new FormData();

            if ($len == 0) {
                return false;
            } else {
                var fileAccaccept = $this.attr('accaccept');
                var fileType = $input.files[0].type;
                var type = (fileType.substr(fileType.lastIndexOf("/") + 1)).toLowerCase();

                if (!type || fileAccaccept.indexOf(type) == -1) {
                    $.notify({
                        message: '您上传图片的类型不符合(.jpg|.jpeg|.gif|.png|.bmp)',
                    }, {
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        type: 'success'
                    });
                    l.destroy();
                    return false;
                }
                formFile.append("file", $input.files[0]);
            }

            var data = formFile;

            $.ajax({
                url: "{:url('index/upload')}",
                data: data,
                type: "POST",
                dataType: "json",
                //上传文件无需缓存
                cache: false,
                //用于对data参数进行序列化处理 这里必须false
                processData: false,
                //必须
                contentType: false,
                success: function (res) {
                    setTimeout(function () {
                        l.destroy();
                    }, 1e3)
                    if (res.code == 200) {
                        $.notify({
                            message: res.msg
                        }, {
                            placement: {
                                from: "top",
                                align: "center"
                            },
                            type: 'success'
                        });
                        //console.log(res.data[0].filePath);
                        $this.closest('.file-group').find('.file-value').val(res.data.fullPath);
                    } else {
                        $.notify({
                            message: "系统错误"
                        }, {
                            placement: {
                                from: "top",
                                align: "center"
                            },
                            // settings
                            type: 'danger'
                        });
                    }
                },
            });
        });
    });


</script>

</body>

</html>